//
//  HomeOneTableViewCell.m
//  fp
//
//  Created by xingshuai on 2020/11/14.
//

#import "HomeOneTableViewCell.h"

@interface HomeOneTableViewCell ()

@property (nonatomic, strong) UIImageView *liveBackView; // 直播背景
@property (nonatomic, strong) UIImageView *playView;     // 直播
@property (nonatomic, strong) UILabel *playLabel;        // 直播标题
@property (nonatomic, strong) UIButton *baseBtn;         // 基础课程
@property (nonatomic, strong) UIButton *suZhiBtn;        // 素质教育
@property (nonatomic, strong) UIButton *schoolBtn;       // 校师佳课
@property (nonatomic, strong) UIButton *myRoomBtn;       // 我的课程
@property (nonatomic, strong) UIButton *historyBtn;      // 播放历史

@end

@implementation HomeOneTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView  {
    static NSString *identifier = @"XAHomeOneCellID";
    id cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self creatHomeOneCellUI];
    }
    return self;
}

-(void)creatHomeOneCellUI {
    self.liveBackView = [[UIImageView alloc]init];
    self.liveBackView.userInteractionEnabled = YES;
    self.liveBackView.image = [UIImage imageNamed:@"home_live_bg"];
    [self.contentView addSubview:self.liveBackView];
    [self.liveBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self.contentView);
        make.width.mas_offset(ScreenWidth/2.3);
        make.height.mas_equalTo(self.liveBackView.mas_width).dividedBy(1.3);
    }];
    
    self.playView = [[UIImageView alloc]init];
    self.playView.userInteractionEnabled = YES;
    self.playView.image = [UIImage imageNamed:@"def_img-1"];
    self.playView.contentMode = UIViewContentModeScaleAspectFill;
    self.playView.layer.cornerRadius = 10;
    self.playView.layer.masksToBounds = YES;
    [self.liveBackView addSubview:self.playView];
    [self.playView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self.liveBackView).offset(10);
        make.right.equalTo(self.liveBackView).offset(-10);
        make.bottom.equalTo(self.liveBackView).offset(-XS_FONT(45));
    }];
    
    self.playLabel = [[UILabel alloc]init];
    self.playLabel.text = @"二十四节气国学启蒙 语文-单元五";
    self.playLabel.textColor = [UIColor whiteColor];
    self.playLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleMedium size:16];
    [self.liveBackView addSubview:self.playLabel];
    [self.playLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.playView);
        make.right.equalTo(self.playView.mas_right).offset(-XS_FONT(80));
        make.top.equalTo(self.playView.mas_bottom);
        make.bottom.equalTo(self.liveBackView);
    }];
    
    self.baseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.baseBtn setTitle:@"基础课程" forState:UIControlStateNormal];
    self.baseBtn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleSemibold size:22];
    self.baseBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    self.baseBtn.titleEdgeInsets = UIEdgeInsetsMake(0, XS_FONT(20), 0, 0);
    [self.baseBtn setBackgroundImage:[UIImage imageNamed:@"bg-ource"] forState:UIControlStateNormal];
    self.baseBtn.tag = 100;
    [self.baseBtn addTarget:self action:@selector(clickBtnType:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.baseBtn];
    [self.baseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.liveBackView.mas_right).offset(10);
        make.top.equalTo(self.contentView);
        make.width.mas_offset(ScreenWidth/3.14);
        make.height.mas_equalTo(self.baseBtn.mas_width).dividedBy(1.97);
    }];
    
    self.suZhiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.suZhiBtn setTitle:@"素质教育" forState:UIControlStateNormal];
    self.suZhiBtn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleSemibold size:22];
    self.suZhiBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    self.suZhiBtn.titleEdgeInsets = UIEdgeInsetsMake(0, XS_FONT(15), 0, 0);
    [self.suZhiBtn setBackgroundImage:[UIImage imageNamed:@"bg-eduation"] forState:UIControlStateNormal];
    self.suZhiBtn.tag = 101;
    [self.suZhiBtn addTarget:self action:@selector(clickBtnType:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.suZhiBtn];
    [self.suZhiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseBtn.mas_right);
        make.right.equalTo(self.contentView);
        make.height.equalTo(self.baseBtn.mas_height);
    }];
    
    self.schoolBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.schoolBtn setTitle:@"校师佳课" forState:UIControlStateNormal];
    self.schoolBtn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleSemibold size:22];
    self.schoolBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    self.schoolBtn.titleEdgeInsets = UIEdgeInsetsMake(0, XS_FONT(20), 0, 0);
    [self.schoolBtn setBackgroundImage:[UIImage imageNamed:@"bg-school"] forState:UIControlStateNormal];
    self.schoolBtn.tag = 102;
    [self.schoolBtn addTarget:self action:@selector(clickBtnType:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.schoolBtn];
    [self.schoolBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseBtn.mas_left);
        make.top.equalTo(self.baseBtn.mas_bottom).offset(10);
        make.bottom.equalTo(self.liveBackView.mas_bottom);
        make.width.mas_equalTo(self.schoolBtn.mas_height).multipliedBy(1.35);
    }];
    
    self.myRoomBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.myRoomBtn setTitle:@"我的课程" forState:UIControlStateNormal];
    self.myRoomBtn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleSemibold size:22];
    self.myRoomBtn.titleEdgeInsets = UIEdgeInsetsMake(0, XS_FONT(45), 0, 0);
    [self.myRoomBtn setBackgroundImage:[UIImage imageNamed:@"bg-classroom"] forState:UIControlStateNormal];
    self.myRoomBtn.tag = 103;
    [self.myRoomBtn addTarget:self action:@selector(clickBtnType:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.myRoomBtn];
    [self.myRoomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.schoolBtn.mas_right).offset(3);
        make.top.equalTo(self.baseBtn.mas_bottom).offset(10);
        make.right.equalTo(self.contentView);
        make.height.mas_equalTo(self.schoolBtn.mas_height).dividedBy(2).offset(-2.5);
    }];
    
    self.historyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.historyBtn setTitle:@"播放历史" forState:UIControlStateNormal];
    self.historyBtn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleSemibold size:22];
    self.historyBtn.titleEdgeInsets = UIEdgeInsetsMake(0, XS_FONT(45), 0, 0);
    [self.historyBtn setBackgroundImage:[UIImage imageNamed:@"bg-history"] forState:UIControlStateNormal];
    self.historyBtn.tag = 104;
    [self.historyBtn addTarget:self action:@selector(clickBtnType:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.historyBtn];
    [self.historyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.schoolBtn.mas_right).offset(3);
        make.top.equalTo(self.myRoomBtn.mas_bottom).offset(5);
        make.right.bottom.equalTo(self.contentView);
    }];
}

-(void)clickBtnType:(UIButton *)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickButtonTypeTag:)]) {
        [self.delegate clickButtonTypeTag:sender.tag];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
